import re

batWenRegex = re.compile(r'Bat(wo)?man')
mo1 = batWenRegex.search('The Adventures of Batman')
print(mo1.group())
mo2 = batWenRegex.search('The Adventures of Batwoman')
print(mo2.group())

phoneRegex = re.compile(r'(\d\d\d-)?\d\d\d-\d\d\d\d')
mo3 = phoneRegex.search('My number is 455-457-8238')
print(mo3.group())
mo4 = phoneRegex.search('My number is 457-8238')
print(mo4.group())

batXingRegex = re.compile(r'Bat(wo)*man')
mo5 = batXingRegex.search('The Adventures of Batman')
print(mo5.group())
mo6 = batXingRegex.search('The Adventures of Batwoman')
print(mo6.group())
mo7 = batXingRegex.search('The Adventures of Batwowowowowowowowoman')
print(mo7.group())
# 注：只显示一个wo
print(mo7.group(1))

batJiaRegex = re.compile(r'Bat(wo)+man')
mo8 = batJiaRegex.search('The Adventures of Batwowowowowowowowoman')
print(mo8.group())
mo9 = batJiaRegex.search('The Adventures of Batwoman')
print(mo9.group())
mo10 = batJiaRegex.search('The Adventures of Batman')
print(mo10)

hahaRegex = re.compile(r'(Ha){3}')
mo11 = hahaRegex.search('HHHEIeheiheiheihahahaHaHaHa')
print(mo11.group())
mo12 = hahaRegex.search('HaHa')
print(mo12)

heRegex = re.compile(r'(He){1,}')
mo13 = heRegex.search('13456^%&*HeHefljwefjoijoHeHeHe')
# 匹配第一项
print(mo13.group())
